package com.pyh.libray.log;

import android.util.Log;

import androidx.annotation.NonNull;

public class PConsolePrinter implements PLogPrinter {
    @Override
    public void print(@NonNull PLogConfig config, int level, String tag, @NonNull String printString) {
        int len = printString.length();
        int maxLine = PLogConfig.LINE_MAX_STRING;
        int countOfSub = len / maxLine;
        // 哨兵添加与移除思想

        if (len != 0 && len % maxLine > 0) {
            countOfSub++;
        }
        for (int i = 0; i < countOfSub - 1; i++) {
            Log.println(level, tag, printString.substring(i * maxLine, (i + 1) * maxLine));
        }
        String lastLineString = printString.substring((countOfSub - 1) * maxLine, len);
        Log.println(level, tag, lastLineString);
    }
}
